package com.brave.edu.manager.dao;

import com.brave.edu.manager.domian.Teacher;

public class TeacherDao {
    private static Teacher[] Tea = new Teacher[5];

    public Teacher[] findAllTeacher() {
        return Tea;
    }

    public boolean addTeacher(Teacher tea) {
        int index = -1;
        for (int i = 0; i < Tea.length; i++) {
            Teacher Teacher = Tea[i];
            if (Teacher == null) {
                index = i;
                break;
            }
        }
        if (index == -1) {
            return false;
        } else {
            Tea[index] = tea;
            return true;
        }
    }

    public void deleteTeacherId(String deleId) {
        int index = getIndex(deleId);
        Tea[index] = null;
    }

    private int getIndex(String deleId) {
        int index = -1;
        for (int i = 0; i < Tea.length; i++) {
            Teacher Teacher = Tea[i];
            if (Teacher != null && Teacher.getId().equals(deleId)) {
                index = i;
                break;
            }
        }
        return index;
    }


    public void updateTeacher(String updateId, Teacher newTea) {
        int index = getIndex(updateId);
        Tea[index] = newTea;
    }
}
